package com.gx.mxbbx.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gx.mxbbx.dao.AreaMapper;
import com.gx.mxbbx.po.Area;
import com.gx.mxbbx.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.sql.Timestamp;
import java.util.List;

@Service
@Transactional
public class AreaServiceImpl implements AreaService {

    @Autowired
    private AreaMapper areaMapper;

    public PageInfo<Area> getAllArea(String areaName, Integer currentPage, Integer limit) {
        PageHelper.startPage(currentPage, limit);
        List<Area> list = areaMapper.getAllArea(areaName);
        PageInfo<Area> pageInfo = new PageInfo<Area>(list);
        return pageInfo;
    }

    public List<Area> getAreaTree(String areaName) {
        /*        System.out.println("getAreaTree"+areaMapper.getAreaTree(areaName));*/
        return areaMapper.getAreaTree(areaName);

    }

    public void areaadd(Area area) {
        area.setCreateTime(new Timestamp(System.currentTimeMillis()));
        area.setUpdateTime(new Timestamp(System.currentTimeMillis()));
        areaMapper.areaadd(area);
    }

    public Area getareaById(Integer id) {
        Area area = areaMapper.getareaById(id);
        return area;
    }

    public void areaedit(Area area) {
        area.setUpdateTime(new Timestamp(System.currentTimeMillis()));
        areaMapper.areaedit(area);
    }

    public void areadelete(Integer id) {
        areaMapper.areadelete(id);
    }

}
